.TH "frovedis::logistic_regression_model<T>" "" "" "" ""
.SH NAME
.PP
\f[C]logistic_regression_model<T>\f[] \- A data structure used in
modeling the outputs of the frovedis logistic regression algorithm.
.SH SYNOPSIS
.PP
\f[C]#include\ <frovedis/ml/glm/linear_model.hpp>\f[]
.SS Constructors
.PP
logistic_regression_model ()
.PD 0
.P
.PD
logistic_regression_model (size_t num_ftr, T intercpt=0.0, T
threshold=0.5)
.PD 0
.P
.PD
logistic_regression_model (const \f[C]logistic_regression_model<T>\f[]&
model)
.PD 0
.P
.PD
logistic_regression_model (\f[C]logistic_regression_model<T>\f[]&&
model)
.SS Overloaded Operators
.PP
\f[C]logistic_regression_model<T>\f[]& operator= (const
\f[C]logistic_regression_model<T>\f[]& model)
.PD 0
.P
.PD
\f[C]logistic_regression_model<T>\f[]& operator=
(\f[C]logistic_regression_model<T>\f[]&& model)
.PD 0
.P
.PD
\f[C]logistic_regression_model<T>\f[] operator+ (const
\f[C]logistic_regression_model<T>\f[]& model) const
.PD 0
.P
.PD
\f[C]logistic_regression_model<T>\f[] operator\- (const
\f[C]logistic_regression_model<T>\f[]& model) const
.PD 0
.P
.PD
void operator+= (const \f[C]logistic_regression_model<T>\f[]& model)
.PD 0
.P
.PD
void operator\-= (const \f[C]logistic_regression_model<T>\f[]& model)
.SS Public Member Functions
.PP
\f[C]std::vector<T>\f[] predict (DATA_MATRIX& mat)
.PD 0
.P
.PD
\f[C]std::vector<T>\f[] predict_probability (DATA_MATRIX& mat)
.PD 0
.P
.PD
void set_threshold (T threshold)
.PD 0
.P
.PD
size_t get_num_features () const
.PD 0
.P
.PD
void save (const std::string& path) const
.PD 0
.P
.PD
void savebinary (const std::string& path) const
.PD 0
.P
.PD
void load (const std::string& path) const
.PD 0
.P
.PD
void loadbinary (const std::string& path) const
.PD 0
.P
.PD
void debug_print() const
.PD 0
.P
.PD
\f[C]node_local<logistic_regression_model<T>>\f[] broadcast ()
.SH DESCRIPTION
.PP
\f[C]logistic_regression_model<T>\f[] models the output of the frovedis
logistic regression algorithm, the trainer interface of which aims to
optimize an initial model and outputs the same after optimization.
This model has the below structure:
.IP
.nf
\f[C]
template\ <class\ T>\ 
struct\ logistic_regression_model\ {
\ \ std::vector<T>\ weight;\ //\ the\ weight\ vector\ associated\ with\ each\ input\ training\ features
\ \ T\ intercept;\ \ \ \ \ \ \ \ \ \ \ //\ the\ bias\ intercept\ term
\ \ T\ threshold;\ \ \ \ \ \ \ \ \ \ \ //\ the\ threshold\ value\ used\ in\ prediction
\ \ SERIALIZE\ (weight,\ intercept,\ threshold)
};
\f[]
.fi
.PP
This is a template based data structure, where "T" is supposed to be
"float" (single\-precision) or "double" (double\-precision).
Note this is a serialized data structure.
The detailed description can be found in subsequent sections.
.SS Constructor Documentation
.SS logistic_regression_model ()
.PP
Default constructor.
It creates an empty logistic regression model with default "intercept"
value as 0.0 and default "threshold" value as 0.5.
.SS logistic_regression_model (size_t num_ftr, T intercept=0.0, T
threshold=0.5)
.PP
Parameterized constructor.
It accepts the number\-of\-features input from the user and allocates
the memory for the model of the same size.
If no initial value of the "intercept" is provided, it considers the
default value as 0.0.
If no "threshold" value is provided, it considers the default value as
0.5.
.SS logistic_regression_model (const
\f[C]logistic_regression_model<T>\f[]& model)
.PP
Copy constructor.
It accepts an lvalue object of the same type and deep\-copies the same
in the newly constructed object.
.SS logistic_regression_model (\f[C]logistic_regression_model<T>\f[]&&
model)
.PP
Move constructor.
It accepts an rvalue object of the same type and instead of copying, it
moves the contents in the newly constructed object.
.SS Overloaded Operator Documentation
.SS \f[C]logistic_regression_model<T>\f[]& operator= (const
\f[C]logistic_regression_model<T>\f[]& model)
.PP
It deep\-copies the contents of the input lvalue model into the
left\-hand side model of the assignment operator "=".
.SS \f[C]logistic_regression_model<T>\f[]& operator=
(\f[C]logistic_regression_model<T>\f[]&& model)
.PP
Instead of copying, it moves the contents of the input rvalue model into
the left\-hand side model of the assignment operator "=".
.SS \f[C]logistic_regression_model<T>\f[] operator+ (const
\f[C]logistic_regression_model<T>\f[]& model) const
.PP
This operator is used to add two logistic regression models and outputs
the resultant model.
If m1 and m2 are two models, expression like "m1 + m2" can easily be
evaluated on them.
.SS \f[C]logistic_regression_model<T>\f[] operator\- (const
\f[C]logistic_regression_model<T>\f[]& model) const
.PP
This operator is used to subtract two logistic regression models and
outputs the resultant model.
If m1 and m2 are two models, expression like "m1 \- m2" can easily be
evaluated on them.
.SS void operator+= (const \f[C]logistic_regression_model<T>\f[]& model)
.PP
This operator is used to add two logistic regression models.
But instead of returning a new model, it updates the target model with
the resultant model.
If m1 and m2 are two models, then "m1 += m2" will add m2 with m1 and
update m1 itself.
.SS void operator\-= (const \f[C]logistic_regression_model<T>\f[]&
model)
.PP
This operator is used to subtract two logistic regression models.
But instead of returning a new model, it updates the target model with
the resultant model.
If m1 and m2 are two models, then "m1 \-= m2" will subtract m2 from m1
and update m1 itself.
.SS Pubic Member Function Documentation
.SS \f[C]std::vector<T>\f[] predict (DATA_MATRIX& mat)
.PP
This function is used on a trained model (after training is done) to
predict the unknown output labels based on the given input matrix.
It uses prediction logic according to logistic regression algorithm.
.PP
This function expects any input data matrix which provides an overloaded
multiply "*" operator with a vector type object.
E.g., if "v" is an object of \f[C]std::vector<T>\f[] type, then "mat *
v" should be supported and it should return the resultant vector of the
type \f[C]std::vector<T>\f[].
DATA_MATRIX can be \f[C]frovedis::crs_matrix_local<T>\f[],
\f[C]frovedis::ell_matrix_local<T>\f[] etc.
.PP
On succesful prediction, this function returns the predicted values in
the form of \f[C]std::vector<T>\f[].
Currently, it supports only binary prediction in the form of 1 (yes) and
\-1 (no).
It will throw an exception, if any error occurs.
.SS \f[C]std::vector<T>\f[] predict_probability (DATA_MATRIX& mat)
.PP
This function is also used on trained model (after training is done) to
predict the unknown output labels based on the given input matrix.
But instead of returning yes/no predictions, it returns the raw
probabilities in the form of \f[C]std::vector<T>\f[] corresponsing to
each new feature vector in the given matrix.
Like predict(), it can also accept any data matrix, if support of "*"
operator with a vector is provided for that matrix.
.SS void set_threshold (T threshold)
.PP
It sets threshold value of the target model with the provided value.
It will throw an exception, if negative value is provided.
.SS size_t get_num_features () const
.PP
It returns the number\-of\-features in the target model.
.SS void save (const std::string& path) const
.PP
It saves the target model in the specified path in simple text format.
It will throw an exception, if any error occurs during the save
operation.
.SS void savebinary (const std::string& path) const
.PP
It saves the target model in the specified path in (little\-endian)
binary data format.
It will throw an exception, if any error occurs during the save
operation.
.SS void load (const std::string& path) const
.PP
It loads the target logistic regression model from the data in specified
text file.
It will throw an exception, if any error occurs during the load
operation.
.SS void loadbinary (const std::string& path) const
.PP
It loads the target logistic regression model from the data in specified
(little\-endian) binary file.
It will throw an exception, if any error occurs during the load
operation.
.SS void debug_print() const
.PP
It prints the contents of the model on the user terminal.
It is mainly useful for debugging purpose.
.SS \f[C]node_local<logistic_regression_model<T>>\f[] broadcast ()
.PP
It broadcasts the target model to all the participating MPI processes
(worker nodes) in the system.
This is an efficient (as it does not involve the serialization overhead
of the model weight vector) implementation than simple
"frovedis:broadcast(model)" call.
.SS Public Data Member Documentation
.SS weight
.PP
An object of \f[C]std::vector<T>\f[] type.
It is used to store the weight/theta components associated with each
training features.
.SS intercept
.PP
A "T" type object (mainly "float" or "double").
It is used to store the bias intercept term of the model.
.SS threshold
.PP
A "T" type object (mainly "float" or "double").
It is used to hold the threshold value used in prediction.
.SH SEE ALSO
.PP
linear_regression_model, svm_model
